#!/usr/bin/python
import subprocess

# seed constans
SEED_LEN_MIN = 5
SEED_LEN_MAX = 20

# hash table constants
SKIP_HASH_GEN = True
REF_GENOME_NAME = "genome.fasta"

# read hotspot constans
READS_FILE = "genome.fasta.dat"


#
# hash table setup from the reference REF_GENOME_NAME
#
if(not SKIP_HASH_GEN):
	print "GENERATING HASH TABLES FROM REFERNECE READ"

	hash_log = open("hash.log", 'w')
	for i in range(SEED_LEN_MIN,SEED_LEN_MAX + 1):
		print "\nNow working on Seed: %i" % i;
		hash_log.write('\n***SeedLength: %i\n' % i);
		hash_log.flush();
		call (["./LongHashTable", REF_GENOME_NAME, (REF_GENOME_NAME + ".ht." + str(i) ), str(i)], stdout=hash_log);
	hash_log.close()

#
# find the hotspots for each read in READ_FILE
#
unique_num = 0 # used to add a make each read unique
reads = open(READS_FILE, 'r+')
for line in reads:
	for i in range(SEED_LEN_MIN,SEED_LEN_MAX + 1):
		p = subprocess.Popen(["./read_hotspots", "genome.fasta.ht." + str(i), line], stdout=subprocess.PIPE)
		out = p.communicate()
		# create the output files for plotting
		output = open("seed_" + str(i) + READS_FILE + ".dat", 'w')
		
	# run the gnuplot file to create the plot for the 